<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app"></div>

  <!-- <script src="../../dist/vue.global.js"></script> -->
  <script>
    const createAppAPI = (render) => {
      return function createApp(rootComponent) {
        const app = {
          mount(rootContainer) {
            const container = document.querySelector(rootContainer)
            const vnode = createVNode(rootComponent)
            render(vnode, container)
          }
        }
        return app
      }
    }
    const createVNode = rootComponent => {
      const vnode = document.createDocumentFragment()
      const h1 = document.createElement('h1')
      h1.innerText = 'vue3初始化流程'
      const p = document.createElement('p')
      p.innerText = rootComponent.data().foo
      vnode.appendChild(h1)
      vnode.appendChild(p)
      return vnode
    }
    const createRenderer = (options) => {
      const render = (vnode, container) => {
        container.appendChild(vnode)
      }
      return {
        render,
        createApp: createAppAPI(render)
      }
    }
    const renderer = createRenderer({})
    const Vue = {
      createApp(options) {
        return renderer.createApp(options)
      }
    }

    Vue.createApp({
      data() {
        return {
          foo: 'hello, vue3!'
        }
      }
    }).mount('#app')
  </script>
</body>

</html>